// components/recommend-goods/recommend-goods.js
var myBehavior = require('../behavior.js')

Component({
  behaviors: [myBehavior],
  /**
   * 组件的属性列表
   * @param { Boolean } showRecommendGoods 是否显示组件
   * @param { Array } data 组件数据
   */
  properties: {
    showRecommendGoods:{
      type:Boolean,
      value:null
    },
    data:{
      type:null,
      value:null
    },
    specNum:{
      type:Number,
      value:1
    },
    maxSpecNum:{
      type:Number,
      value:null
    }
  },
 
  /**
   * 组件的初始数据
   */
  data: {
    specNum:1
  },

  /**
   * 组件的方法列表
   */
  methods: {
    _radio(e){
      let td = this.data,item = e.currentTarget.dataset.index;
      td.data[item].checked = !td.data[item].checked;
      this.setData({
        data:td.data
      });
    },
    _minus(e){
      let td = this.data, addItem = e.currentTarget.dataset.index;
      td.data[addItem].number == 1 ? 1 : td.data[addItem].number --;
      this.setData({
        data: td.data
      });
    },
    _stepperAdd: function (e) {
      let td = this.data, addItem = e.currentTarget.dataset.index;
      td.data[addItem].number >= td.maxSpecNum ? td.data[addItem].number = td.maxSpecNum : td.data[addItem].number ++;
      this.setData({
        data: td.data
      });
    },
    _buttonLeft(){
      this.setData({
        showRecommendGoods:false
      });
    },
    _formSubmit(e){
      let td = this.data, dataItem = e.detail.value,formData = [];
      for(let i in dataItem){
        formData.push(td.data[dataItem[i]]);
      }
      this.triggerEvent("formSubmit", { formData},{})
    }
  }
})
